{{ extend './layout/main.html'}}   
{{block 'title'}}增加音乐{{/block}} 
{{block 'content'}}
    <div class="container">
        <div class="page-header">
            <h1><a href="/">我的音乐</a><small>--增加音乐</small> 
                <button type="button" class="btn btn-success" onclick="self.location=document.referrer;">返回</button>            
            <h1>    
        </div>
    </div>
    <div class="container">
        <form id="form" method="post" action="/">
            
            <div class="form-group">
                <label for="">歌曲标题</label>
                <input v-model="title" type="text" name="title" class="form-control" placeholder="请输入歌曲标题">
            </div>
            <div class="form-group">
                <label for="">歌曲时长</label>
                <input v-model="time" type="text" name="time" class="form-control" placeholder="请输入歌曲时长">
            </div>
            <div class="form-group">
                <label for="">歌手</label>
                <input v-model="singer" type="text" name="singer" class="form-control" placeholder="请输入歌手姓名">
            </div>
            <div class="form-group">
                <label for="">歌曲文件</label>
                <input type="file" name="file" ref="file" id="file">
                <p class="help-block">请上传歌曲文件.</p>
            </div>
            <div class="form-group">
                <label for="">歌词文件</label>
                <input type="file" name="filelrc" ref="filelrc" id="filelrc">
                <p class="help-block">请上传歌词文件.</p>
            </div>
            <button type="button" class="btn btn-success" @click.stop="addMusic">点击添加</button>
        </form>
    </div>
{{/block}}
{{block 'vue'}}
<script>
    new Vue({
        el:"#app",
        data:{
            title:"",
            singer:"",
            time:"",
            file:"",
            filelrc:"",
            type:1,
        },
        methods:{
            addMusic(){
                let _this = this;
                var FormData1 = new FormData();
                FormData1.append("title",this.title);
                FormData1.append("singer",this.singer);
                FormData1.append("time",this.time);
                FormData1.append("file",this.$refs.file.files["0"]);
                FormData1.append("filelrc",this.$refs.filelrc.files["0"]);
                axios({
                    method: 'post',
                    url: '/music/add',
                    data:FormData1,

                }).then(function (response) {
                    let {errno,msg} = (response.data);
                    if(!errno){
                        _this.title = "";
                        _this.singer = "";
                        _this.time = "";
                        // this.$refs.file.value="";
                        window.alert("添加成功");
                        var file = document.getElementById("file");
                        var filelrc = document.getElementById("filelrc");
                        if (file.outerHTML) {
                            file.outerHTML = file.outerHTML;
                            filelrc.outerHTML = filelrc.outerHTML;

                        } else { // FF(包括3.5)
                            file.value = "";
                            filelrc.value = "";                            
                        }
                    }else{
                        window.alert(msg)
                    }
                });
            },
            goback(){

            }
        },
        created() {
            
        },
        mounted() {
            
        },
    })
</script>
{{/block}}
